﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace LucyDemo
{
	abstract class AbstractDemo
	{
		IEnumerable<FieldInfo> GetFields() {
			return this.GetType().GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
		}

		public Dictionary<string, string[]> Parameters {
			get {
				return GetFields()
					.ToDictionary(f => f.Name, f => new string[]{ f.FieldType.Name, f.GetValue(this).ToString()} );
			}
			set {
				GetFields()
					.Join(value, o => o.Name, i => i.Key, (o, i) => new { Field = o, Value = i.Value })
					.All(f =>
					{
						f.Field.SetValue(this, Convert.ChangeType(f.Value[1], f.Field.FieldType));
						return true;
					});
			}
		}

		public abstract string Info();

		public abstract string Run(bool enableLocalProcessing);
	}
}
